<?php
  class Core_Correios_Enderecos{
	  public $_objInformacoes;
	
	  public function buscarCep($strCep){
	    $objCurl = curl_init();
	    curl_setopt_array(
        $objCurl, array(
          CURLOPT_URL       => "http://www.buscacep.correios.com.br/servicos/dnec/consultaEnderecoAction.do",
	        CURLOPT_POST      => TRUE,
	        CURLOPT_POSTFIELDS    => "relaxation={$strCep}&TipoCep=ALL&semelhante=N&Metodo=listaLogradouro&TipoConsulta=relaxation&StartRow=1&EndRow=10&cfm=1",
	        CURLOPT_RETURNTRANSFER  => TRUE
	      )
	    );
	    $strResponse = curl_exec($objCurl);
	    curl_close($objCurl);
	    preg_match_all("/>(.*?)<\/td>/", $strResponse, $arrMatches);
	    return $arrMatches[1];
	  }
	
	  public function retornaInformacoesCep($strCep){
	    $arrInformacoes = $this->buscarCep($strCep);
	    $this->_objInformacoes = new Core_Correios_Informacoes();
	    $this->_objInformacoes->setLogradouro($arrInformacoes[0]);
	    $this->_objInformacoes->setBairro($arrInformacoes[1]);
	    $this->_objInformacoes->setLocalidade($arrInformacoes[2]);
	    $this->_objInformacoes->setUf($arrInformacoes[3]);
	    $this->_objInformacoes->setCep($arrInformacoes[4]);
	  }
  }